package com.zxy.demo.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;


public class Slf4jTest {

    private static final Logger log = LoggerFactory.getLogger(Slf4jTest.class);

    public static void main(String[] args) {
        log.info("abc");

        // 占位符里面的方法也会被执行的，需要配置日志级别为INFO及以上才能看到效果
        long curTime = System.currentTimeMillis();
        log.debug("getResult {}", getResult());
        log.info("getResult time:{}ms", (System.currentTimeMillis() - curTime));

        curTime = System.currentTimeMillis();
        if (log.isDebugEnabled()) {
            log.debug("getResult {}", getResult());
        }
        log.info("getResult isDebugEnabled time:{}ms", (System.currentTimeMillis() - curTime));
    }

    public static String getResult() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "Hello";
    }

}
